'use strict';

let xhr = new XMLHttpRequest();

function Get(vm){
	this.vm = vm;

}

Get.prototype = {

	success: function(m){
		this.vm.$message({
			message: m,
			type: 'success'
		})
	},

	error: function(m){
		this.vm.$message.error(m)
	},

	tips: function(m,t){
		this.vm.$message({
			message: m,
			type: t
		})
	},

	ajax: function(url, data, method, callback){
		xhr.onreadystatechange = function(){
			if (xhr.readyState === 4 && xhr.status === 200) {
				callback(xhr.responseText);
			} else {
				console.log(xhr.error);
				this.error(xhr.error.msg)
			}
		}
		xhr.open(method, url, true);
		xhr.setRequestHeader('Content-Type', 'application/json');
		xhr.send(data);
	}








}



Vue.prototype.G = function(){
	return new Get(this)
}

